package www.bwsensing.com.service.collection.database;

import org.springframework.stereotype.Component;
import www.bwsensing.com.common.CollectionService;
import www.bwsensing.com.common.cache.RedisService;
import www.bwsensing.com.common.mqtt.MqttPushClient;
import www.bwsensing.com.common.netty.NettyTcpServerFactory;
import www.bwsensing.com.common.netty.NettyUdpServerFactory;
import www.bwsensing.com.service.collection.database.dataobject.ServiceData;
import www.bwsensing.com.service.collection.database.dataobject.TranslateType;

import javax.annotation.Resource;


/**
 * @author macos-zyj
 */
@Component
public class CollectionServiceFactory {

    @Resource
    private RedisService redisService;

    @Resource
    private MqttPushClient mqttPushClient;

    public  CollectionService getCollectionService(ServiceData serviceData){
        TranslateType translateType = TranslateType.getTransactionType(serviceData.getReceiveType());
        switch (translateType){
            case UDP:
                return NettyUdpServerFactory.getNettyServer(serviceData,redisService,mqttPushClient);
            case TCP:
                return NettyTcpServerFactory.getNettyServer(serviceData,mqttPushClient);
            default:
                return null;
        }
    }
}
